package com.zhiyou100.blog.filter;

import com.alibaba.druid.filter.FilterChain;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

//@WebFilter(urlPatterns = "/*",
//        dispatcherTypes = {DispatcherType.ERROR,
//                DispatcherType.FORWARD,
//                DispatcherType.INCLUDE,
//                DispatcherType.REQUEST})
public class CharacterEncodingFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        req.setCharacterEncoding("UTF-8");
        chain.doFilter(req, response);
    }
}
